package com.unicom.wostore.dsp.controller;

import com.unicom.wostore.dsp.utils.HttpUtil;
import net.sf.json.JSONObject;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;

/**
 * Created by Huangjie on 2017/3/6.
 */
@RequestMapping("miuiad")
public class MiuiadAction {


    @RequestMapping(value = "getAds",method = {RequestMethod.POST},consumes = "application/json")
    @ResponseBody
    public JSONObject getAds(@RequestBody JSONObject jsonObj, HttpServletRequest httpServletRequest){

        //String response = HttpUtil.get("http://ad.miuiad.com/agent/sspGetAd?p=0&n=1&mt=2&chkey=oElEwDIdPEh6sOD8&akey=MbB5f92ibIyH670d3157F32wkoUmy37e&bundle=org.ws.test&wct=0&pt=0&w=320&h=50&tp=iPhone6&brd=Apple&lang=zh_CN&os=1&osv=9.2&sv=0&appn=null&appv=null&sw=320&sh=586&sden=2&ori=2&cr=46000&lon=0&lat=0&lt=1451541137805&nt=2&dt=1&uuid=025604BF-C1FD-4F7E-B3A0-1901DC679859&imei=&imsi=null&idfa=025604BF-C1FD-4F7E-B3A0-1901DC679859&mac=f0dce2f329c6&idfv=A3C588CC-BA00-4417-8B86-4BDC983A66C3&anid=&jb=0&ua=Mozilla%2F5.0+%28iPhone%3B+CPU+iPhone+OS+8_0+like+Mac+OS+X%29+AppleWebKit%2F600.1.3+%28KHTML%2C+like+Gecko%29+Version%2F8.0+Mobile%2F12A4345d+Safari%2F600.1.4&time=1451541137806&ip=null&baseUrlStr=null&vt=1&token=bd7678abf381465132f706a55b86e9e9&testMode=false&tokenMatch=true&hostUrl=http%3A%2F%2F127.0.0.1%3A8080%2FWebSystem%2F",null);

        return null;
    }

    public static void main(String[] args){
        //String response = HttpUtil.get("http://www.baidu.com",null);
        //String response = HttpUtil.get("http://ad.miuiad.com/agent/sspGetAd?p=0&n=1&mt=2&chkey=oElEwDIdPEh6sOD8&akey=MbB5f92ibIyH670d3157F32wkoUmy37e&bundle=org.ws.test&wct=0&pt=0&w=320&h=50&tp=iPhone6&brd=Apple&lang=zh_CN&os=1&osv=9.2&sv=0&appn=null&appv=null&sw=320&sh=586&sden=2&ori=2&cr=46000&lon=0&lat=0&lt=1451541137805&nt=2&dt=1&uuid=025604BF-C1FD-4F7E-B3A0-1901DC679859&imei=&imsi=null&idfa=025604BF-C1FD-4F7E-B3A0-1901DC679859&mac=f0dce2f329c6&idfv=A3C588CC-BA00-4417-8B86-4BDC983A66C3&anid=&jb=0&ua=Mozilla%2F5.0+%28iPhone%3B+CPU+iPhone+OS+8_0+like+Mac+OS+X%29+AppleWebKit%2F600.1.3+%28KHTML%2C+like+Gecko%29+Version%2F8.0+Mobile%2F12A4345d+Safari%2F600.1.4&time=1451541137806&ip=null&baseUrlStr=null&vt=1&token=bd7678abf381465132f706a55b86e9e9&testMode=false&tokenMatch=true&hostUrl=http%3A%2F%2F127.0.0.1%3A8080%2FWebSystem%2F",null);

        Map paramMap = new HashMap();
        paramMap.put("n","1");
        paramMap.put("mt","2");
        paramMap.put("chkey","oElEwDIdPEh6sOD8");
        paramMap.put("akey","MbB5f92ibIyH670d3157F32wkoUmy37e");

        paramMap.put("pt","1");
        paramMap.put("appv","1.0.2");
        paramMap.put("appn","FightingGame");

        paramMap.put("os","0");
        paramMap.put("osv","6.0.1");
        paramMap.put("cr","46001");

        paramMap.put("dt","4");

        paramMap.put("uuid","025604BF-C1FD-4F7E-B3A0-1901DC679859");
        paramMap.put("idfa","dada-xasd-3213-2132");
        paramMap.put("mac","3213-3123-312dsad");
        paramMap.put("imei","dsadsadsa");
        paramMap.put("bundle","com.ws.demo");
        System.out.print(new Date().getTime());
        paramMap.put("time",new Date().getTime()+"");






//+uuid+idfa+imei+os+cr+bundle+time+akey+chkey+CH密钥)
        String str = "Iou51pd3DW116706316aCLJ0mHEk4379" +paramMap.get("uuid") + paramMap.get("idfa") + paramMap.get("imei") + paramMap.get("os") +
                paramMap.get("bundle") + paramMap.get("time") + paramMap.get("akey") + paramMap.get("chkey")+"BBwzClzyTFxgRz88JLP50p9rROTKecnS";
        String token = HttpUtil.EncoderByMD5(str);


        paramMap.put("token",token);//



        paramMap.put("wct","0");
        paramMap.put("w","0");
        paramMap.put("h","0");
        paramMap.put("tp","");
        paramMap.put("brd","");
        paramMap.put("sw","0");
        paramMap.put("sh","0");
        paramMap.put("sden","0");
        paramMap.put("ori","0");


        paramMap.put("lon","0");
        paramMap.put("lat","0");
        paramMap.put("lt","0");
        paramMap.put("nt","0");
        paramMap.put("idfv","");
        paramMap.put("anid","");
        paramMap.put("jb","");
        paramMap.put("ua","");
        paramMap.put("lang","");

        String response = HttpUtil.get("http://ad.miuiad.com/agent/sspGetAd",paramMap);







        System.out.print(response);
    }
}
